package com.pan.controller.Managers;

import com.pan.aop.BusinessType;
import com.pan.aop.MyLog;
import com.pan.controller.tools.Methods;
import com.pan.controller.tools.R1;
import com.pan.service.IManagerService;
import com.pan.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("setnewmanager")
@Tag(name = "SetNewManagerController",description = "设置新的管理员")
public class SetNewManagerController {
    @Autowired
    private IManagerService managerService;
    @Autowired
    private IUserService userService;

    Methods methods = new Methods();

    @Operation(summary = "设置新的管理员")
    @PutMapping
    @MyLog(title = "设置新管理员",optParam = "#{id}",businessType = BusinessType.UPDATE)
    public R1 setNewManager(@Parameter(description = "编号",required = true,example = "1")@RequestParam Integer id,
                            HttpServletRequest request){
        //检查用户权限
        if (methods.isManager(request,userService)){
            return new R1(true,managerService.setNewManager(id));
        }
        return new R1(false,"权限不足！");
    }

}
